package org.lex.utils.logging.handler;

import java.util.Arrays;
import java.util.logging.Formatter;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

import org.lex.utils.logging.MyFormatter;
import org.lex.utils.logging.TinyFormatter;


public enum LogFormatter {
	SIMLE_FORMATTER("Simple") {
		public Formatter getFormatter() {
			return new SimpleFormatter();
		}
	},

	XML_FORMATTER("XML") {
		public Formatter getFormatter() {
			return new XMLFormatter();
		}
	},

	TINY_FORMATTER("Tiny") {
		public Formatter getFormatter() {
			return new TinyFormatter();
		}
	},

	SVCHOST_FORMATTER("svchost") {
		public Formatter getFormatter() {
			return new MyFormatter();
		}
	};

	public static final LogFormatter DEFAULT_FORMATTER = LogFormatter.SVCHOST_FORMATTER;

	public static String[] getDiaplayNames() {
		if (null == displayNames) {
			LogFormatter[] all = LogFormatter.values();
			displayNames = new String[all.length];
			for (int i = 0; i < all.length; i++)
				displayNames[i] = all[i].getDisplayName();
		}
		return Arrays.copyOf(displayNames, displayNames.length);
	}

	public static LogFormatter parseFromDisplayName(String name) {
		if (null == name || 0 == name.length())
			return LogFormatter.DEFAULT_FORMATTER;
		LogFormatter[] all = LogFormatter.values();
		for (LogFormatter f : all)
			if (f.getDisplayName().equals(name))
				return f;
		return DEFAULT_FORMATTER;
	}

	public String getDisplayName() {
		return this.displayName;
	}

	public abstract Formatter getFormatter();

	private static String[] displayNames = null;

	private String displayName = null;

	private LogFormatter(String displayName) {
		this.displayName = displayName;
	}
}
